package com.xy.tianyu.utils

import java.util.*

/**
 * @time 2020/9/17 15:14
 * @class 描述:
 */
object StringUtils {
    /**
     * 获取随机字母加数字字符串
     */
    fun getRandomString(length: Int): String? {
        val str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
        val random = Random()
        val sb = StringBuffer()
        for (i in 0 until length) {
            val number: Int = random.nextInt(62)
            sb.append(str[number])
        }
        return sb.toString()
    }

    /**
     * 获取随机数字字符串
     */
    fun getRandomNumString(length: Int):String{
        val str = "0123456789"
        val random = Random()
        val sb = StringBuffer()
        for (i in 0 until length) {
            val number: Int = random.nextInt(10)
            sb.append(str[number])
        }
        return sb.toString()
    }

    /**
     * 获得随机字符串
     */
    fun getRandomWordString(length: Int):String{
        val str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        val random = Random()
        val sb = StringBuffer()
        for (i in 0 until length) {
            val number: Int = random.nextInt(52)
            sb.append(str[number])
        }
        return sb.toString()
    }
}